package hos.http;

/**
 * <p>Title: HttpStringUtils </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-03-29 13:27
 */
public class HttpStringUtils {

    public static String substringAfter(String target, String delimiter) {
        return substringAfter(target, delimiter, target);
    }

    public static String substringAfter(String target, String delimiter, String missingDelimiterValue) {
        int index = target.indexOf(delimiter);
        if (index == -1) {
            return missingDelimiterValue;
        } else
            return target.substring(index + delimiter.length());
    }

    public static String substringBefore(String target, String delimiter) {
        return substringBefore(target, delimiter, target);
    }

    public static String substringBefore(String target, String delimiter, String missingDelimiterValue) {
        int index = target.indexOf(delimiter);
        if (index == -1) {
            return missingDelimiterValue;
        } else
            return target.substring(0, index);
    }

    public static String substringBeforeLast(String target, char delimiter) {
        return substringBeforeLast(target, delimiter, target);
    }

    public static String substringAfterLast(String target, char delimiter) {
        return substringAfterLast(target, delimiter, target);
    }

    public static String substringBeforeLast(String target, char delimiter, String missingDelimiterValue) {
        int index = target.lastIndexOf(delimiter);
        if (index == -1) return missingDelimiterValue;
        else return target.substring(0, index);
    }

    public static String substringAfterLast(String target, char delimiter, String missingDelimiterValue) {
        int index = target.lastIndexOf(delimiter);
        if (index == -1) return missingDelimiterValue;
        else return target.substring(index + 1);
    }

}
